package com.deng.hadoop.mapreduce.demo.weather;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * Created By DengLibin
 * Date: 19-4-3
 * Time: 上午10:05
 * Desc: mapper任务  输入的key-value : 行(偏移量)-该行文本 输出的key-value:天气对象-温度
 */
public class WeatherMapper extends Mapper<LongWritable, Text, TianQi, IntWritable> {

    private  TianQi tianQi = new TianQi();
    private  IntWritable wenDu = new IntWritable();
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        //输入value的格式 1949-10-01 14:12:32 34c
        String s = value.toString();
        System.out.println("map输入:"+s);
        Integer year = Integer.parseInt(s.substring(0,4));
        Integer month = Integer.parseInt(s.substring(5,7));
        Integer day = Integer.parseInt(s.substring(8,10));
        Integer temperature = Integer.parseInt(s.substring(20,22));
        System.out.println("year:"+year+",month:"+month+",day:"+day+",temperature:"+temperature);
        tianQi.setYear(year);
        tianQi.setMonth(month);
        tianQi.setDay(day);
        tianQi.setTemperature(temperature);
        wenDu.set(temperature);
        context.write(tianQi, wenDu);
    }
}
